﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KCMS.DataAcsess.Interfaces;
using KCMS.DataAcsess.Entitys;
namespace KCMS.DataAcsess.Engine
{
    public class MenuItemManager:IMenuItemManager
    {
        protected DataClassesDataContext db = new DataBaseConnect().DataBase;
        private DataManager<MenuItemEntity> dm = new DataManager<MenuItemEntity>();
        public Entitys.MenuItemEntity getById(Guid id)
        {
            return (from t in db.GetTable<MenuItemEntity>()
                    where t.Id.Equals(id)
                    select t).SingleOrDefault();
        }

        public IEnumerable<Entitys.MenuItemEntity> getAll()
        {
            //return (from t in db.GetTable<MenuItemEntity>()
            //        select t).ToList();
            return dm.getAll();
        }



        public void update(MenuItemEntity menuItem)
        {
            db = new DataBaseConnect().DataBase;
            var old = getById(menuItem.Id);
            old.CopyPropyties(menuItem);
            db.SubmitChanges();
        }

        public void delete(Guid id)
        {
            dm.delete(id);
        }

        public void save(MenuItemEntity menuItem)
        {
            dm.save(menuItem);
        }
    }
}
